﻿using Farming.Domain;
using Farming.Domain.CustomClass;
using Farming.Domain.Traceabilities;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;

namespace Farming.EntityFarmeworkCore
{
    public class FarmingDbContext:DbContext
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        public FarmingDbContext(DbContextOptions<FarmingDbContext> options, IHttpContextAccessor httpContextAccessor) :base(options) 
        {
            _httpContextAccessor = httpContextAccessor;

        }
        public DbSet<Admin> Admins { get; set; }
        
        public DbSet<HusbandryMessage> HusbandryMessages { get; set; }
        public DbSet<CustomActionModel> CustomActionModels { get; set; }
        public DbSet<TraceabilityIndex> TraceabilityIndex { get; set; }
        public DbSet<SoftDeleteEntity> SoftDeleteEntities { get; set; }
        public DbSet<SlaughterImages> SlaughterImageses { get; set; }
        public DbSet<SlaughterInformation> SlaughterInformations { get; set; }
        public DbSet<HealthInformation> HealthInformations { get; set; }
        public DbSet<HusbandryEnterpriseImages> HusbandryEnterpriseImageses { get; set; }
        public DbSet<HusbandryEnterprise> HusbandryEnterprises { get; set; }
        public DbSet<DeepProcessing> DeepProcessings { get; set; }
        public DbSet<DeepProcessingImages> DeepProcessingImagess { get; set; }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Admin>().HasQueryFilter(x => x.IsDeleted == false);
            modelBuilder.Entity<TraceabilityIndex>().HasQueryFilter(x => x.IsDeleted == false);
            //modelBuilder.Entity<Admin>(d =>
            //{
            //    d.Property(d => d.UserName).HasMaxLength(50);
            //});
            //数据播种
            //modelBuilder.Entity<Admin>().HasData(
            // new Admin
            // {
            //     UserName = "Admin",
            //     PassWord = Guid.NewGuid().ToString("n"),
            //     AdminId = 1,
            //     CreateById = 1,
            //     CreateByName = "Admin",
            //     CreateTime = DateTime.Now,
            //     IsDeleted = false
            // },
            // new Admin
            // {
            //     UserName = "Admin2",
            //     PassWord = Guid.NewGuid().ToString("n"),
            //     AdminId = 2,
            //     CreateById = 2,
            //     CreateByName = "Admin2",
            //     CreateTime = DateTime.Now.AddDays(6),
            //     IsDeleted = false
            // }

            // );

            base.OnModelCreating(modelBuilder);
        }
       

    }
}